package principal;

import espace_physique.VuePopup;
import fichiers.Element;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;


public class ControleurArbreBoutonDroit extends MouseAdapter{
    
   private JTree arbre;
   private JPopupMenu popup;
    
    public ControleurArbreBoutonDroit(JTree arbre,JPopupMenu popup){
        
        this.popup=popup;
        this.arbre=arbre;
    }
    
    public void mouseClicked(MouseEvent e) {
        // clic sur le bouton droit
        if(e.getButton() == MouseEvent.BUTTON3) {
            try {
             TreePath path=arbre.getPathForLocation(e.getX(),e.getY());
             DefaultMutableTreeNode noeud= ((DefaultMutableTreeNode)path.getLastPathComponent());          
             Element el=(Element)noeud.getUserObject();
             this.arbre.setSelectionPath(path);
             popup.show(e.getComponent(), e.getX(), e.getY());

             
            } catch (NullPointerException ex) {
//This means the user did not click on a node
            }
        }
    }
    
}   
